<template>
  <div class="tiku">
    <el-tabs v-model="activeName" @tab-click="handleClick" class="tiku-w">
      <el-tab-pane label="题库" name="first">
        <div class="tk-search"></div>
        <div class="tk-table tk">
          <fieldset>
            <legend>试题题库:</legend>
            <div>
              <el-table
                :data="tableData"
                class="tiku-w-table"
                style="width: 100%"
              >
                <el-table-column
                  prop="id"
                  label="ID"
                  width="180"
                  align="center"
                />
                <el-table-column
                  prop="questionName"
                  label="题库名称"
                  align="center"
                  show-overflow-tooltip
                />
                <!-- <el-table-column
              prop="Operations"
              label="试题个数"
              align="center"
            /> -->
                <el-table-column label="操作" width="250" align="center">
                  <template #default="scope">
                    <el-button @click="editTk(scope.row)" size="small"
                      >编辑</el-button
                    >
                    <el-button size="small" @click="delTk(scope.row)"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
              <div class="czBtn">
                <el-button @click="addTk">新增</el-button>
              </div>
            </div>
          </fieldset>
          <fieldset>
            <legend>错接线题库:</legend>
            <div>
              <el-table
                class="tiku-w-table"
                :data="tableDataWiring"
                style="width: 100%"
              >
                <el-table-column
                  prop="id"
                  label="ID"
                  width="180"
                  align="center"
                />
                <el-table-column
                  prop="questionName"
                  label="题库名称"
                  align="center"
                  show-overflow-tooltip
                />
                <!-- <el-table-column
              prop="Operations"
              label="试题个数"
              align="center"
            /> -->
                <el-table-column label="操作" width="250" align="center">
                  <template #default="scope">
                    <el-button @click="editTk(scope.row, 1)" size="small"
                      >编辑</el-button
                    >
                    <el-button size="small" @click="delTk(scope.row, 1)"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
              <div class="czBtn">
                <el-button @click="addTk(1)">新增</el-button>
              </div>
            </div>
          </fieldset>
        </div>
      </el-tab-pane>
      <el-tab-pane label="试题" name="second">
        <div class="st-search">
          <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="选择题库">
              <el-select
                filterable
                v-model="formInline.bankId"
                placeholder="选择题库"
                clearable
                @change="selectData"
              >
                <el-option
                  v-for="item in tableData"
                  :label="item.questionName"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
            <!-- <el-form-item label="选择试题">
              <el-select
                v-model="formInline.st"
                placeholder="选择试题"
                clearable
              >
                <el-option label="Zone one" value="shanghai" />
                <el-option label="Zone two" value="beijing" />
              </el-select>
            </el-form-item> -->
            <el-form-item>
              <el-button @click="onSubmit">导入</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="st-table">
          <el-table
            highlight-current-row
            :data="stTableData"
            @row-click="rowClick"
            style="width: 100%"
            class="tiku-w-table2"
          >
            <!--            <el-table-column-->
            <!--              prop="dnlz"-->
            <!--              label="总电能"-->
            <!--              width="80"-->
            <!--              align="center"-->
            <!--            >-->
            <!--              <template #default="scope">-->
            <!--                <el-input disabled v-model="scope.row.dnlz"></el-input>-->
            <!--              </template>-->
            <!--            </el-table-column>-->
            <el-table-column
              prop="dnl1"
              label="尖电能"
              width="80"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.dnl1"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="dnl2"
              label="峰电能"
              width="80"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.dnl2"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="dnl3"
              label="平电能"
              width="80"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.dnl3"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="dnl4"
              label="谷电能"
              width="80"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.dnl4"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="dnl5"
              label="深谷电能"
              width="80"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.dnl5"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="last1"
              label="上月尖电能"
              width="80"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.last1"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="last2"
              label="上月峰电能"
              width="80"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.last2"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="last3"
              label="上月平电能"
              width="80"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.last3"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="last4"
              label="上月谷电能"
              width="80"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.last4"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="last5"
              label="上月深谷电能"
              width="80"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.last5"></el-input>
              </template>
            </el-table-column>
            <!--            <el-table-column-->
            <!--              prop="lastTotal"-->
            <!--              label="上月总电能"-->
            <!--              width="80"-->
            <!--              align="center"-->
            <!--            >-->
            <!--              <template #default="scope">-->
            <!--                <el-input disabled v-model="scope.row.lastTotal"></el-input>-->
            <!--              </template>-->
            <!--            </el-table-column>-->
            <el-table-column
              prop="dnlzwg"
              label="无功总电能"
              width="80"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.dnlzwg"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="lastTotalwg"
              label="上月无功总电能"
              width="80"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.lastTotalwg"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vx1"
              label="尖需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vx1"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vx2"
              label="峰需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vx2"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vx3"
              label="平需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vx3"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vx4"
              label="谷需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vx4"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vx5"
              label="深谷需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vx5"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vxz"
              label="总需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vxz"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vxLast1"
              label="上月尖需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vxLast1"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vxLast2"
              label="上月峰需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vxLast2"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vxLast3"
              label="上月平需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vxLast3"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vxLast4"
              label="上月谷需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vxLast4"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vxLast5"
              label="上月深谷需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vxLast5"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vxLastTotal"
              label="上月总需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vxLastTotal"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vx1wg"
              label="无功尖需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vx1wg"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vx2wg"
              label="无功峰需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vx2wg"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vx3wg"
              label="无功平需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vx3wg"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vx4wg"
              label="无功谷需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vx4wg"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vx5wg"
              label="无功深谷需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vx5wg"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vxzwg"
              label="无功总需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vxzwg"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vxLast1wg"
              label="上月无功尖需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vxLast1wg"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vxLast2wg"
              label="上月无功峰需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vxLast2wg"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vxLast3wg"
              label="上月无功平需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vxLast3wg"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vxLast4wg"
              label="上月无功谷需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vxLast4wg"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vxLast5wg"
              label="上月无功深谷需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vxLast5wg"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="vxLastTotalwg"
              label="上月无功总需量"
              width="220"
              align="center"
            >
              <template #default="scope">
                <el-input v-model="scope.row.vxLastTotalwg"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              fixed="right"
              label="操作"
              width="250"
              align="center"
            >
              <template #default="scope">
                <!-- <el-button link type="primary" size="small" @click="handleClick"
                  >删除</el-button
                > -->
                <span v-if="scope.row.sp1" style="color: red"
                  >表位：{{ scope.row.sp1 }}</span
                >
                <el-button
                  style="margin-left: 10px"
                  @click="choseBw(scope.$index)"
                  size="small"
                  >选择表位</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <div class="czBtn">
            <el-button @click="addSTTable">增加数据</el-button>
            <el-button @click="delSTTable">删除数据</el-button>
            <el-button @click="save">保存</el-button>
            <el-button @click="send">发送到表位</el-button>
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane label="错接线题库" name="three">
        <div class="st-search">
          <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="选择题库" props="newBankId">
              <el-select
                filterable
                v-model="formInline.newBankId"
                placeholder="选择题库"
                clearable
                @change="selectWiringData"
              >
                <el-option
                  v-for="item in tableDataWiring"
                  :label="item.questionName"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-form>
        </div>
        <div class="tk-table">
          <el-table
            @row-click="rowClick1"
            :data="wiringData"
            style="width: 100%"
            class="tiku-w-table2"
            highlight-current-row
            border
          >
            <el-table-column
              prop="faultName"
              show-overflow-tooltip
              label="选中内容"
              align="center"
            />
            <el-table-column label="表位" width="250" align="center">
              <template #default="scope">
                <span v-if="scope.row.position" style="color: red"
                  >表位：{{ scope.row.position }}</span
                >
                <el-button
                  style="margin-left: 10px"
                  @click="choseBw(scope.$index, 1)"
                  size="small"
                  >选择表位</el-button
                >
              </template>
            </el-table-column>
            <el-table-column label="选择故障" width="250" align="center">
              <template #default="scope">
                <el-button
                  style="margin-left: 10px"
                  @click="choseWiring(scope.$index)"
                  size="small"
                  >选择故障</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <div class="czBtn">
            <el-button @click="addSTTable(1)">增加数据</el-button>
            <el-button @click="delSTTable(1)">删除数据</el-button>
            <el-button @click="save1">保存</el-button>
            <el-button @click="send1">发送到表位</el-button>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>
    <!-- 新增题库 -->
    <TKForm
      :form="form"
      :title="title"
      :tkType="tkType"
      :tkFormVisible="tkFormVisible"
      @is-show="isShow"
    ></TKForm>
    <!-- 新增试题 -->
    <!--选择表位-->
    <TablePositionTk
      :type="type"
      :meterId="meterId"
      :meterWiringId="meterWiringId"
      @changeBw="changeBw"
    ></TablePositionTk>
    <!-- 选择故障 -->
    <TableWiringTk @changeWiring="changeWiring"></TableWiringTk>
    <!-- 导入模板 -->
    <RecordImport
      @changeTable="changeTable"
      @close="close"
      :dialogImportVisible="dialogImportVisible"
    ></RecordImport>
  </div>
</template>
<script setup>
import { ref, reactive, onMounted } from "vue";
import { useAppStore, paramsDataStore } from "@/stores";
import { useFetchData } from "@/utils/fetch.js";
import { storeToRefs } from "pinia";
import { ElMessage } from "element-plus";
import TKForm from "@/components/dialog/tkForm.vue";
import TablePositionTk from "@/components/dialog/tablePositionTk.vue";
import TableWiringTk from "@/components/dialog/tableWiringTk.vue";
import RecordImport from "@/components/dialog/recordImport.vue";
import {
  questionSave,
  questionBankList,
  miswiringBankList,
  questionBankRemove,
  miswiringBankRemove,
  questionList,
  meterMeterDataCollection,
  meterDataCollectionById,
  meterFzbSingleFault,
  miswiringSave,
  meterRelayFault,
  miswiringList,
} from "@/api/source.js";

const useApp = useAppStore();
let {
  organStructure,
  tbWiringTkVisible,
  tbPositionTkVisible,
  meterIds,
  meterWiringIds,
  loading,
  currentPlanId,
} = storeToRefs(useApp);

const activeName = ref("first");
const tkFormVisible = ref(false);
const dialogImportVisible = ref(false);
const tableData = ref([]);
const tableDataWiring = ref([]);
const stTableData = ref([]);
const wiringData = ref([]);
const type = ref(0);
const tkType = ref(0);
const title = ref();
const formInline = reactive({
  bankId: "",
  newBankId: "",
  region: "",
  date: "",
});
const form = reactive({
  questionName: "",
});
const etableData = ref([
  {
    prop: "byzxygfl1",
    parm0: "readPositiveActiveEnergy",
    parm01: "writePositiveActiveEnergy",
    parm1: 1,
    parm2: 0,
    parm3: "",
    label: "当前正向有功尖电能",
    content: "",
    props: "dnl1",
  },
  {
    prop: "byzxygfl1",
    parm0: "readPositiveActiveEnergy",
    parm01: "writeCombinedReactivePower1ElectricEnergy",
    parm1: 1,
    parm2: 0,
    parm3: "",
    label: "当前正向无功尖电能",
    content: "",
    props: "dnl1wg",
  },
  {
    prop: "byzxygfl2",
    parm0: "readPositiveActiveEnergy",
    parm01: "writePositiveActiveEnergy",
    parm1: 2,
    parm2: 0,
    parm3: "",
    label: "当前正向有功峰电能",
    content: "",
    props: "dnl2",
  },
  {
    prop: "byzxygfl2",
    parm0: "readPositiveActiveEnergy",
    parm01: "writeCombinedReactivePower1ElectricEnergy",
    parm1: 2,
    parm2: 0,
    parm3: "",
    label: "当前正向无功峰电能",
    content: "",
    props: "dnl2wg",
  },
  {
    prop: "byzxygfl3",
    parm0: "readPositiveActiveEnergy",
    parm01: "writePositiveActiveEnergy",
    parm1: 3,
    parm2: 0,
    parm3: "",
    label: "当前正向有功平电能",
    content: "",
    props: "dnl3",
  },
  {
    prop: "byzxygfl3",
    parm0: "readPositiveActiveEnergy",
    parm01: "writeCombinedReactivePower1ElectricEnergy",
    parm1: 3,
    parm2: 0,
    parm3: "",
    label: "当前正向有功平电能",
    content: "",
    props: "dnl3wg",
  },
  {
    prop: "byzxygfl4",
    parm0: "readPositiveActiveEnergy",
    parm01: "writePositiveActiveEnergy",
    parm1: 4,
    parm2: 0,
    parm3: "",
    label: "当前正向有功谷电能",
    content: "",
    props: "dnl4",
  },
  {
    prop: "byzxygfl5",
    parm0: "readPositiveActiveEnergy",
    parm01: "writePositiveActiveEnergy",
    parm1: 5,
    parm2: 0,
    parm3: "",
    label: "当前正向有功深谷电能",
    content: "",
    props: "dnl5",
  },
  {
    prop: "byzxygfl4",
    parm0: "readPositiveActiveEnergy",
    parm01: "writeCombinedReactivePower1ElectricEnergy",
    parm1: 4,
    parm2: 0,
    parm3: "",
    label: "当前正向有功谷电能",
    content: "",
    props: "dnl4wg",
  },
  {
    prop: "byzxygfl4",
    parm0: "readPositiveActiveEnergy",
    parm01: "writeCombinedReactivePower1ElectricEnergy",
    parm1: 5,
    parm2: 0,
    parm3: "",
    label: "当前正向有功深谷电能",
    content: "",
    props: "dnl5wg",
  },
  {
    prop: "byzxygz",
    parm0: "readPositiveActiveEnergy",
    parm01: "writePositiveActiveEnergy",
    parm1: 0,
    parm2: 0,
    parm3: "",
    label: "当前正向有功总电能",
    content: "",
    type: "1",
    props: "dnlz",
  },
  {
    prop: "byzxygz",
    parm0: "readPositiveActiveEnergy",
    parm01: "writeCombinedReactivePower1ElectricEnergy",
    parm1: 0,
    parm2: 0,
    parm3: "",
    label: "当前正向有功总电能",
    content: "",
    type: "1",
    props: "dnlzwg",
  },
  {
    prop: "syzxygfl1",
    label: "上月正向有功尖电能",
    parm0: "readPositiveActiveEnergy",
    parm01: "writePositiveActiveEnergy",
    parm1: 1,
    parm2: 1,
    parm3: "",
    content: "",
    props: "last1",
  },
  {
    prop: "syzxygfl1",
    label: "上月正向有功尖电能",
    parm0: "readPositiveActiveEnergy",
    parm01: "writeCombinedReactivePower1ElectricEnergy",
    parm1: 1,
    parm2: 1,
    parm3: "",
    content: "",
    props: "last1wg",
  },
  {
    prop: "syzxygfl2",
    label: "上月正向有功峰电能",
    parm0: "readPositiveActiveEnergy",
    parm01: "writePositiveActiveEnergy",
    parm1: 2,
    parm2: 1,
    parm3: "",
    content: "",
    props: "last2",
  },
  {
    prop: "syzxygfl2",
    label: "上月正向有功峰电能",
    parm0: "readPositiveActiveEnergy",
    parm01: "writeCombinedReactivePower1ElectricEnergy",
    parm1: 2,
    parm2: 1,
    parm3: "",
    content: "",
    props: "last2wg",
  },
  {
    prop: "syzxygfl3",
    label: "上月正向有功平电能",
    parm0: "readPositiveActiveEnergy",
    parm01: "writePositiveActiveEnergy",
    parm1: 3,
    parm2: 1,
    parm3: "",
    content: "",
    props: "last3",
  },
  {
    prop: "syzxygfl3",
    label: "上月正向有功平电能",
    parm0: "readPositiveActiveEnergy",
    parm01: "writeCombinedReactivePower1ElectricEnergy",
    parm1: 3,
    parm2: 1,
    parm3: "",
    content: "",
    props: "last3wg",
  },
  {
    prop: "syzxygfl4",
    label: "上月正向有功谷电能",
    parm0: "readPositiveActiveEnergy",
    parm01: "writePositiveActiveEnergy",
    parm1: 4,
    parm2: 1,
    parm3: "",
    content: "",
    props: "last4",
  },
  {
    prop: "syzxygfl5",
    label: "上月正向有功深谷电能",
    parm0: "readPositiveActiveEnergy",
    parm01: "writePositiveActiveEnergy",
    parm1: 5,
    parm2: 1,
    parm3: "",
    content: "",
    props: "last5",
  },
  {
    prop: "syzxygfl4",
    label: "上月正向有功谷电能",
    parm0: "readPositiveActiveEnergy",
    parm01: "writeCombinedReactivePower1ElectricEnergy",
    parm1: 4,
    parm2: 1,
    parm3: "",
    content: "",
    props: "last4wg",
  },
  {
    prop: "syzxygfl5",
    label: "上月正向有功深谷电能",
    parm0: "readPositiveActiveEnergy",
    parm01: "writeCombinedReactivePower1ElectricEnergy",
    parm1: 5,
    parm2: 1,
    parm3: "",
    content: "",
    props: "last5wg",
  },
  {
    prop: "syzxygfl",
    label: "上月正向有功总电能",
    parm0: "readPositiveActiveEnergy",
    parm01: "writePositiveActiveEnergy",
    parm1: 0,
    parm2: 1,
    parm3: "",
    content: "",
    type: "1",
    props: "lastTotal",
  },
  {
    prop: "syzxygfl",
    label: "上月正向有功总电能",
    parm0: "readPositiveActiveEnergy",
    parm01: "writeCombinedReactivePower1ElectricEnergy",
    parm1: 0,
    parm2: 1,
    parm3: "",
    content: "",
    type: "1",
    props: "lastTotalwg",
  },
  {
    content: "",
    label: "(当前)正向有功总最大需量及发生时间",
    prop: "zxygzzdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm1: 0,
    parm2: 0,
    parm3: "",
    props: "vxz",
  },
  {
    content: "",
    label: "(当前)正向有功总最大需量及发生时间",
    prop: "zxygzzdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfCombinedReactivePower1",
    parm1: 0,
    parm2: 0,
    parm3: "",
    props: "vxzwg",
  },
  {
    content: "",
    label: "(当前)正向有功费率1最大需量及发生时间",
    prop: "zxygfl1zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm1: 1,
    parm2: 0,
    parm3: "",
    props: "vx1",
  },
  {
    content: "",
    label: "(当前)正向有功费率1最大需量及发生时间",
    prop: "zxygfl1zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfCombinedReactivePower1",
    parm1: 1,
    parm2: 0,
    parm3: "",
    props: "vx1wg",
  },
  {
    content: "",
    label: "(当前)正向有功费率2最大需量及发生时间",
    prop: "zxygfl2zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm1: 2,
    parm2: 0,
    parm3: "",
    props: "vx2",
  },
  {
    content: "",
    label: "(当前)正向有功费率2最大需量及发生时间",
    prop: "zxygfl2zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfCombinedReactivePower1",
    parm1: 2,
    parm2: 0,
    parm3: "",
    props: "vx2wg",
  },
  {
    content: "",
    label: "(当前)正向有功费率3最大需量及发生时间",
    prop: "zxygfl3zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm1: 3,
    parm2: 0,
    parm3: "",
    props: "vx3",
  },
  {
    content: "",
    label: "(当前)正向有功费率3最大需量及发生时间",
    prop: "zxygfl3zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfCombinedReactivePower1",
    parm1: 3,
    parm2: 0,
    parm3: "",
    props: "vx3wg",
  },
  {
    content: "",
    label: "(当前)正向有功费率4最大需量及发生时间",
    prop: "zxygfl4zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm1: 4,
    parm2: 0,
    parm3: "",
    props: "vx4",
  },
  {
    content: "",
    label: "(当前)正向有功费率5最大需量及发生时间",
    prop: "zxygfl4zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm1: 5,
    parm2: 0,
    parm3: "",
    props: "vx5",
  },
  {
    content: "",
    label: "(当前)正向有功费率4最大需量及发生时间",
    prop: "zxygfl4zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfCombinedReactivePower1",
    parm1: 4,
    parm2: 0,
    parm3: "",
    props: "vx4wg",
  },
  {
    content: "",
    label: "(当前)正向有功费率5最大需量及发生时间",
    prop: "zxygfl4zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfCombinedReactivePower1",
    parm1: 5,
    parm2: 0,
    parm3: "",
    props: "vx5wg",
  },
  {
    content: "",
    label: "(上月)正向有功总最大需量及发生时间",
    prop: "syzxygzzdxljfssj",
    // prop: "zxygzzdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm1: 0,
    parm2: 1,
    parm3: "",
    props: "vxLastTotal",
  },
  {
    content: "",
    label: "(上月)正向有功总最大需量及发生时间",
    prop: "syzxygzzdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfCombinedReactivePower1",
    parm1: 0,
    parm2: 1,
    parm3: "",
    props: "vxLastTotalwg",
  },
  {
    content: "",
    label: "(上月)正向有功费率1最大需量及发生时间",
    prop: "syzxygfl1zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm1: 1,
    parm2: 1,
    parm3: "",
    props: "vxLast1",
  },
  {
    content: "",
    label: "(上月)正向有功费率1最大需量及发生时间",
    prop: "syzxygfl1zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfCombinedReactivePower1",
    parm1: 1,
    parm2: 1,
    parm3: "",
    props: "vxLast1wg",
  },
  {
    content: "",
    label: "(上月)正向有功费率2最大需量及发生时间",
    prop: "syzxygfl2zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm1: 2,
    parm2: 1,
    parm3: "",
    props: "vxLast2",
  },
  {
    content: "",
    label: "(上月)正向有功费率2最大需量及发生时间",
    prop: "syzxygfl2zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfCombinedReactivePower1",
    parm1: 2,
    parm2: 1,
    parm3: "",
    props: "vxLast2wg",
  },
  {
    content: "",
    label: "(上月)正向有功费率3最大需量及发生时间",
    prop: "syzxygfl3zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm1: 3,
    parm2: 1,
    parm3: "",
    props: "vxLast3",
  },
  {
    content: "",
    label: "(上月)正向有功费率3最大需量及发生时间",
    prop: "syzxygfl3zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfCombinedReactivePower1",
    parm1: 3,
    parm2: 1,
    parm3: "",
    props: "vxLast3wg",
  },
  {
    content: "",
    label: "(上月)正向有功费率4最大需量及发生时间",
    prop: "syzxygfl4zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm1: 4,
    parm2: 1,
    parm3: "",
    props: "vxLast4",
  },
  {
    content: "",
    label: "(上月)正向有功费率5最大需量及发生时间",
    prop: "syzxygfl4zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm1: 5,
    parm2: 1,
    parm3: "",
    props: "vxLast5",
  },
  {
    content: "",
    label: "(上月)正向有功费率4最大需量及发生时间",
    prop: "syzxygfl4zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfCombinedReactivePower1",
    parm1: 4,
    parm2: 1,
    parm3: "",
    props: "vxLast4wg",
  },
  {
    content: "",
    label: "(上月)正向有功费率5最大需量及发生时间",
    prop: "syzxygfl4zdxljfssj",
    parm0: "readMaximumDemandAndOccurrenceTimeOfPositiveActivePower",
    parm01: "writeMaximumDemandAndOccurrenceTimeOfCombinedReactivePower1",
    parm1: 5,
    parm2: 1,
    parm3: "",
    props: "vxLast5wg",
  },
]);
const currentIndex = ref(0);
const currentWiringIndex = ref(0);
const currentData = ref(0);
const currentWiringData = ref(0);
const meterId = ref();
const meterWiringId = ref();
const faultCode = ref();
const faultName = ref();
onMounted(() => {
  initTk(1);
  initTkWiring(1);
});
const initTk = async (type) => {
  // let { result } = useFetchData(questionBankList);
  // setTimeout(() => {
  //   tableData.value = result.value.data;
  //   console.log("异步执行的结果", result);
  // }, 1000); // 模拟异步操作，如Ajax请求，1秒后调用resolve

  await questionBankList()
    .then((res) => {
      tableData.value = res.data;
      formInline.bankId = res.data[0].id;
      if (type === 1) selectData(res.data[0].id);
    })
    .catch((err) => {
      console.log(err);
    });
};
const initTkWiring = async (type) => {
  await miswiringBankList()
    .then((res) => {
      tableDataWiring.value = res.data;
      formInline.newBankId = res.data[0].id;
      if (type === 1) selectWiringData(res.data[0].id);
    })
    .catch((err) => {
      console.log(err);
    });
};
//打开导入
const onSubmit = () => {
  dialogImportVisible.value = true;
};
//关闭导入
const close = () => {
  dialogImportVisible.value = false;
};
const handleClick = (tab, event) => {
  type.value = 0;
  if (tab.props.label === "错接线题库") {
    type.value = 1;
  }
  console.log(tab, event);
};
//新增题库
const addTk = (type) => {
  title.value = "试题题库";
  tkType.value = 0;
  if (type === 1) {
    tkType.value = 1;
    title.value = "错接线题库";
  }
  form.id = "";
  form.questionName = "";
  tkFormVisible.value = true;
};
//编辑题库
const editTk = (row, type) => {
  title.value = "试题题库";
  tkType.value = 0;
  if (type === 1) {
    tkType.value = 1;
    title.value = "错接线题库";
  }
  form.id = row.id;
  form.questionName = row.questionName;
  tkFormVisible.value = true;
  console.log(row);
};
//删除题库
const delTk = (row, type) => {
  //   tkFormVisible.value = true;
  ElMessageBox.confirm("确认要删除?", "警告", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      let parm = {
        id: row.id,
      };
      if (type === 1) {
        doDelWiringTk(parm);
      } else {
        doDelTk(parm);
      }
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "取消删除",
      });
    });
};
const doDelTk = async (parm) => {
  await questionBankRemove(parm)
    .then((res) => {
      ElMessage({
        message: "删除成功",
        type: "success",
      });
      initTk();
    })
    .catch((err) => {
      console.log(err);
      ElMessage({
        message: "删除失败",
        type: "warning",
      });
    });
};
const doDelWiringTk = async (parm) => {
  await miswiringBankRemove(parm)
    .then((res) => {
      ElMessage({
        message: "删除成功",
        type: "success",
      });
      initTkWiring();
    })
    .catch((err) => {
      console.log(err);
      ElMessage({
        message: "删除失败",
        type: "warning",
      });
    });
};
//增加数据
const addSTTable = (type) => {
  if (type === 1) {
    let num = wiringData.value.length + 1;
    let obj = {
      // sp: "试题" + num,
      ids: num,
      faultName: "",
      faultCode: "",
      position: "",
      orgId: "",
    };
    wiringData.value.push(obj);
  } else {
    let num = stTableData.value.length + 1;
    let obj = {
      // sp: "试题" + num,
      ids: num,
      bankId: formInline.bankId,
      dnl1: "",
      dnl2: "",
      dnl3: "",
      dnl4: "",
      dnlz: "",
      last1: "",
      last2: "",
      last3: "",
      last4: "",
      lastTotal: "",
      meterId: "",
      vx1: "",
      vx2: "",
      vx3: "",
      vx4: "",
      vxz: "",
      vxLast1: "",
      vxLast2: "",
      vxLast3: "",
      vxLast4: "",
      vxLastTotal: "",
    };
    stTableData.value.push(obj);
  }
};
const delSTTable = (type) => {
  if (type === 1) {
    // 1.判断有么有选中行
    if (!currentWiringData.value) {
      wiringData.value.pop();
    } else {
      // 2.判断是不是数据库数据
      if (currentWiringData.value.id) {
        let data = wiringData.value.filter(
          (item) => item.id != currentWiringData.value.id
        );
        wiringData.value = data;
        currentWiringData.value = "";
      }
      // 3.根据ids匹配
      if (currentWiringData.value.ids) {
        let data = wiringData.value.filter(
          (item) => item.ids != currentWiringData.value.ids
        );
        wiringData.value = data;
        currentWiringData.value = "";
      }
    }
    meterWiringIds.value = [];
    wiringData.value.forEach((item) => {
      meterWiringIds.value.push(item.position);
    });
  } else {
    // 1.判断有么有选中行
    if (!currentData.value) {
      stTableData.value.pop();
    } else {
      // 2.判断是不是数据库数据
      if (currentData.value.id) {
        let data = stTableData.value.filter(
          (item) => item.id != currentData.value.id
        );
        stTableData.value = data;
        currentData.value = "";
      }
      // 3.根据ids匹配
      if (currentData.value.ids) {
        let data = stTableData.value.filter(
          (item) => item.ids != currentData.value.ids
        );
        stTableData.value = data;
        currentData.value = "";
      }
    }
    meterIds.value = [];
    stTableData.value.forEach((item) => {
      meterIds.value.push(item.meterId);
    });
  }
};
const isShow = () => {
  tkFormVisible.value = false;
  initTk();
  initTkWiring();
};
const cellClick = (row, column) => {
  // console.log("cellClick", row, column.property);
  switch (column.property) {
    case "dnlz":
      row.dnlzState = !row.dnlzState;
      break;
    case "dnl1":
      row.dnl1State = !row.dnl1State;
      break;
    default:
      break;
  }
};
const focusEvent = (row, index, column) => {
  if (column.property === "dnlz") {
    row.oldDnlz = row.dnlz;
  }
  if (column.property === "dnl1") {
    row.oldDnl1 = row.dnl1;
  }
};
const blurEvent = (row, index, column) => {
  switch (column.property) {
    case "dnlz":
      row.dnlzState = !row.dnlzState;
      if (row.oldDnlz !== row.dnlz) {
        updateDevList(row);
      }
      break;
    case "dnl1":
      row.dnl1State = !row.dnl1State;
      if (row.dnl1 !== row.oldDnl1) {
        updateDevList(row);
      }
      break;
    default:
      break;
  }
};
//选择表位弹窗
const choseBw = (val, type) => {
  if (type === 1) {
    currentWiringIndex.value = val;
    meterWiringId.value = wiringData.value[currentWiringIndex.value].position;
  } else {
    currentIndex.value = val;
    meterId.value = stTableData.value[currentIndex.value].meterId;
  }
  tbPositionTkVisible.value = true;
};
//选择表位
const changeBw = (obj) => {
  if (type.value === 1) {
    meterWiringIds.value = [];
    wiringData.value[currentWiringIndex.value].meterId = obj.orgId;
    wiringData.value[currentWiringIndex.value].position = obj.position;
    wiringData.value.forEach((item) => {
      meterWiringIds.value.push(item.position);
    });
  } else {
    meterIds.value = [];
    stTableData.value[currentIndex.value].meterId = obj.orgId;
    stTableData.value[currentIndex.value].sp1 = obj.position;
    stTableData.value.forEach((item) => {
      meterIds.value.push(item.meterId);
    });
  }
};
//选择表位故障
const choseWiring = () => {
  faultCode.value = "";
  faultName.value = "";
  tbWiringTkVisible.value = true;
};
const changeWiring = (obj) => {
  if (faultCode.value) faultCode.value += "," + obj.vps.split(":")[0];
  else faultCode.value = obj.vps.split(":")[0];
  if (faultName.value) faultName.value += ",电压相序:" + obj.vps.split(":")[1];
  else faultName.value = "电压相序:" + obj.vps.split(":")[1];
  if (faultName.value)
    faultName.value += ",相电流线路故障:" + obj.cps.split(":")[1];
  else faultName.value = "相电流线路故障:" + obj.cps.split(":")[1];
  if (faultCode.value) faultCode.value += "," + obj.cps.split(":")[0];
  else faultCode.value = obj.cps.split(":")[0];
  obj.ttype.forEach((item) => {
    if (faultCode.value) faultCode.value += "," + item.split(":")[0];
    else faultCode.value = item.split(":")[0];
    if (faultName.value)
      faultName.value += ",485线路故障:" + item.split(":")[1];
    else faultName.value = "485线路故障:" + item.split(":")[1];
  });
  obj.vlf.forEach((item) => {
    if (faultCode.value) faultCode.value += "," + item.split(":")[0];
    else faultCode.value = item.split(":")[0];
    if (faultName.value)
      faultName.value += ",电压线路故障:" + item.split(":")[1];
    else faultName.value = "电压线路故障:" + item.split(":")[1];
  });
  obj.clf.forEach((item) => {
    if (faultCode.value) faultCode.value += "," + item.split(":")[0];
    else faultCode.value = item.split(":")[0];
    if (faultName.value)
      faultName.value += ",电流线路故障:" + item.split(":")[1];
    else faultName.value = "电流线路故障:" + item.split(":")[1];
  });

  if (wiringData.value[currentWiringIndex.value]) {
    wiringData.value[currentWiringIndex.value].faultName = faultName.value;
    wiringData.value[currentWiringIndex.value].faultCode = faultCode.value;
  }
  console.log(obj, wiringData.value, faultCode.value, faultName.value);
};
const selectData = async (val) => {
  meterIds.value = [];
  let parm = {
    bankId: val,
  };
  await questionList(parm)
    .then((res) => {
      stTableData.value = res.data;
      stTableData.value.forEach((item) => {
        if (item.meterId) {
          meterIds.value.push(item.meterId);
        }
      });
    })
    .catch((err) => {
      console.log(err);
    });
};
const selectWiringData = async (val) => {
  meterWiringIds.value = [];
  let parm = {
    bankId: val,
  };
  await miswiringList(parm)
    .then((res) => {
      wiringData.value = res.data;
      wiringData.value.forEach((item) => {
        if (item.position) {
          meterWiringIds.value.push(item.position);
        }
      });
    })
    .catch((err) => {
      console.log(err);
    });
};
//保存
const save = async () => {
  let num = meterIds.value.length;
  let num1 = stTableData.value.length;
  if (num > 0 && num === num1) {
    //过滤掉删除数据的ids
    stTableData.value.forEach((item, index) => {
      if (item.ids) {
        delete stTableData.value[index].ids;
      }
    });
    await questionSave(stTableData.value)
      .then((res) => {
        console.log(res);
        ElMessage({
          message: "保存成功",
          type: "success",
        });
      })
      .catch((err) => {
        console.log(err);
        ElMessage({
          message: "保存失败",
          type: "warning",
        });
      });
  } else {
    ElMessage({
      message: "请选择表位",
      type: "warning",
    });
  }
};
// 保存表位故障设置
const save1 = async () => {
  let num = meterWiringIds.value.length;
  let num1 = wiringData.value.length;
  if (num > 0 && num === num1) {
    //过滤掉删除数据的ids
    wiringData.value.forEach((item, index) => {
      item.bankId = formInline.newBankId;
      item.planId = currentPlanId.value;
      if (item.ids) {
        delete wiringData.value[index].ids;
        delete wiringData.value[index].orgId;
      }
    });
    await miswiringSave(wiringData.value)
      .then((res) => {
        console.log(res);
        ElMessage({
          message: "保存成功",
          type: "success",
        });
      })
      .catch((err) => {
        console.log(err);
        ElMessage({
          message: "保存失败",
          type: "warning",
        });
      });
  } else {
    ElMessage({
      message: "请选择表位",
      type: "warning",
    });
  }
};
//发送到表位
const send = async () => {
  let parm = [];
  let parm1 = [];
  let arr = [
    "dnlz",
    "lastTotal",
    // "dnlzwg",
    // "lastTotalwg",
    "vxz",
    "vxLastTotal",
    "vxzwg",
    "vxLastTotalwg",
  ];
  let proNum = 0;
  stTableData.value.forEach((item) => {
    //是否单相
    let flag = loopDataPosition(
      organStructure.value[0].children,
      item.sp1,
      [],
      1
    );
    let faultCodes = 39;
    if (flag) faultCodes = 12;
    console.log("item12", item);
    let obj1 = {
      pos: Number(item.sp1),
      planId: currentPlanId.value,
      faultCodes,
    };
    parm1.push(obj1);
    etableData.value.forEach((item1) => {
      if (!arr.includes(item1["props"])) {
        let parm3 = item[item1["props"]];
        if (parm3) {
          let wugong = [
            "writeFirstQuadrantReactiveEnergy",
            "writeSecondQuadrantReactiveEnergy",
            // "writeThirdQuadrantReactiveEnergy",
            // "writeFourthQuadrantReactiveEnergy"
          ];
          console.log('item1["props"]', item1["props"]);
          if (item1["props"] === "dnlzwg") {
            for (const wgMethod of wugong) {
              let parmVal = 0;
              for (let i = 1; i < 6; i++) {
                if (
                  i === 1 &&
                  wgMethod === "writeFirstQuadrantReactiveEnergy"
                ) {
                  parmVal = parm3;
                } else {
                  parmVal = 0;
                }
                let newParm = [i, 0, parmVal];
                let obj = {
                  pos: item.meterId,
                  parm: newParm,
                  methodName: wgMethod,
                  planId: currentPlanId.value,
                };
                parm.push(obj);
              }
            }
          } else if (item1["props"] === "lastTotalwg") {
            for (const wgMethod of wugong) {
              let parmVal = 0;
              for (let i = 1; i < 6; i++) {
                if (
                  i === 1 &&
                  wgMethod === "writeFirstQuadrantReactiveEnergy"
                ) {
                  parmVal = parm3;
                } else {
                  parmVal = 0;
                }
                let newParm = [i, 1, parmVal];
                let obj = {
                  pos: item.meterId,
                  parm: newParm,
                  methodName: wgMethod,
                  planId: currentPlanId.value,
                };
                parm.push(obj);
              }
            }
          } else {
            let newParm = [item1.parm1, item1.parm2, parm3];
            let obj = {
              pos: item.meterId,
              parm: newParm,
              methodName: item1.parm01,
              planId: currentPlanId.value,
            };
            parm.push(obj);
          }
        }
      }
    });
  });
  // console.log(parm, parm1);
  // await meterMeterDataCollectionApi(parm, 0);
  stopRunningFault(parm1, parm, 0);
};
//发送表位故障设置
const send1 = () => {
  let parm = [];
  wiringData.value.forEach((item) => {
    let obj = {
      faultCodes1: item.faultCode,
      planId: currentPlanId.value,
      pos: item.position,
    };
    parm.push(obj);
  });
  meterRelayFaultApi(parm, 0);
};
//表位故障设置
const meterRelayFaultApi = async (params1, i) => {
  loading.value = true;
  let parm = JSON.parse(JSON.stringify(params1[i]));
  await meterRelayFault(parm)
    .then((res) => {})
    .catch(() => {});
  if (++i < params1.length) {
    await meterRelayFaultApi(params1, i); //循环调用
  }
  if (i == params1.length) {
    loading.value = false;
    let msg = "写入成功";
    ElMessage({
      type: "success",
      message: msg,
    });
  }
};
const loopDataPosition = (dataTab = [], pos, tempArr = [], type) => {
  dataTab.forEach((item) => {
    if (item.position === Number(pos)) {
      if (item.wiringType === "单相") {
        tempArr.push(true);
      } else {
        tempArr.push(false);
      }
    } else {
      tempArr.push(false);
    }
    if (item.children != undefined && item.children.length > 0) {
      loopDataPosition(item.children, pos, tempArr, type);
    }
  });
  return tempArr.includes(true);
};
const meterMeterDataCollectionApi = async (params1, i) => {
  loading.value = true;
  let parm = JSON.parse(JSON.stringify(params1[i]));
  await meterDataCollectionById(parm)
    .then((res) => {
      // if (++i < params1.length) {
      //   meterMeterDataCollectionApi(params1, i); //循环调用
      // }
    })
    .catch(() => {});
  if (++i < params1.length) {
    await meterMeterDataCollectionApi(params1, i); //循环调用
  }
  if (i == params1.length) {
    loading.value = false;
    let msg = "写入成功";
    ElMessage({
      type: "success",
      message: msg,
    });
  }
};
//停走故障
const stopRunningFault = async (params1, params2, i) => {
  loading.value = true;
  let parm = JSON.parse(JSON.stringify(params1[i]));
  console.log(parm);
  await meterFzbSingleFault(parm)
    .then((res) => {})
    .catch(() => {});
  if (++i < params1.length) {
    stopRunningFault(params1, params2, i); //循环调用
  }
  if (i === params1.length) {
    await meterMeterDataCollectionApi(params2, 0);
  }
};
const changeTable = (obj) => {
  // stTableData.value = obj;
  obj.forEach((item) => {
    item.bankId = formInline.bankId;
    stTableData.value.push(item);
  });
  dialogImportVisible.value = false;
};
//表格点击
const rowClick = (row) => {
  currentData.value = row;
};
//表格点击
const rowClick1 = (row) => {
  currentWiringData.value = row;
};
</script>

<style lang="scss" scoped>
.st-table {
  margin-top: 10px;
}
.tk-table {
  margin-top: 10px;
}
.tk {
  display: flex;
  justify-content: space-around;
}
.czBtn {
  display: flex;
  justify-content: end;
  margin: 10px 0px;
  margin-right: 10px;
}
</style>
